//
//  AppCacheStorageHelper.swift
//  XiaoweHearingAid
//
//  Created by edy on 2025/6/12.
//

import Foundation

class AppCacheStorageHelper {
    
    // Cache Storage
    class func getCacheStorage<T: Codable>(name: String, valueType: T.Type) -> Storage<String, T>? {
        let cmdId = "创建 Cache Storage"
        let diskConfig = DiskConfig(name: name)
        let memoryConfig = MemoryConfig(expiry: .never, countLimit: 10, totalCostLimit: 10)

        do {
            let storage = try Storage<String, T>(diskConfig: diskConfig, memoryConfig: memoryConfig, transformer: TransformerFactory.forCodable(ofType: T.self))
            
            return storage
        } catch let error {
            log.error("\(cmdId), cacheStorage创建失败，error = \(error.localizedDescription)")
            return nil
        }
    }
    
//    class func cacheStorageSet<T: Codable>(storage: Storage<String, T>?, key: String, value: T) {
//        guard let storage = storage else {
//            return
//        }
//        try? storage.setObject(value, forKey: key)
//    }
//    
//    class func cacheStorageGet<T: Codable>(storage: Storage<String, T>?, key: String) -> T? {
//        guard let storage = storage else {
//            return nil
//        }
//        return try? storage.object(forKey: key)
//    }
    
}
